﻿

using System;
using System.Text;
using System.Reflection;
using Microsoft.Practices.Unity.InterceptionExtension;
using System.Runtime.Caching;

using Microsoft.Practices.EnterpriseLibrary.Caching;
using System.Collections.Generic;

namespace Demo.Infrastructure.Log
{
    /// <summary>
    /// 日志工具
    /// </summary>
    public sealed class LogUtils
    {

        #region private property

        /// <summary>
        /// 日志对象
        /// </summary>
        private ILog log = null;

        #endregion

        #region public property

        /// <summary>
        /// 日志类型
        /// </summary>
        public  LogType Type { get; set; }

        /// <summary>
        /// 日志消息类型
        /// </summary>
        public LogMessageType MessageType { get; set; }

        #endregion

        #region Ctor

        /// <summary>
        /// 构造函数
        /// </summary>
        public LogUtils()
        {
            log = LogFactory.GetLogInstance(Type);
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="type">日志类型</param>
        public LogUtils(LogType type)
        {
            log = LogFactory.GetLogInstance(type);
        }

        #endregion

        #region public Methons

        /// <summary>
        /// 构造实例
        /// </summary>
        /// <param name="type">日志类型</param>
        /// <returns></returns>
        public static LogUtils GetInstance(LogType type = LogType.Text)
        {
            return new LogUtils(type);
        }

        /// <summary>
        /// 构造实例
        /// </summary>
        /// <param name="type">日志类型</param>
        /// <param name="messageType">日志消息类型</param>
        /// <returns></returns>
        public static LogUtils GetInstance(LogType type, LogMessageType messageType)
        {
            var logUtils = new LogUtils(type);
            logUtils.MessageType = messageType;
            return logUtils;
        }

        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="message">日志信息</param>
        public  void Log(string message)
        {
            log.Log("信息类型：" + MessageType.ToString() + "；错误信息：" + message);
        }

        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="ex">异常信息</param>
        public  void Log(Exception ex)
        {
            log.Log("信息类型：" + MessageType.ToString() + "；错误信息：" + ex);
        }

        #endregion

    }

}
